package com.example.shop_2207

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.shop_2207.databinding.ActivityWelBinding
import com.example.shop_2207.login.LoginActivity
import com.example.shop_2207.mvvm.BaseViewActivity
import java.util.Timer
import kotlin.concurrent.timerTask

class WelActivity : BaseViewActivity<ActivityWelBinding>() {
    var time = 5
    lateinit var timer:Timer
    val handler:Handler = Handler()
    override fun getLayout(): Int = R.layout.activity_wel

    override fun initView() {
        //欢迎页只展示一次的代码效果
        /*if(SPUtils.getInstance().getBoolean("isOpen")){
            *//*startActivity(Intent(this@WelActivity,LoginActivity::class.java))*//*
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }else{
            timer = Timer()
            timer.schedule(timerTask {
                handler.post {
                    time--
                    binding.djs.setText("倒计时：$time 秒")
                    if(time==0){
                        *//*startActivity(Intent(this@WelActivity,LoginActivity::class.java))*//*
                        ARouter.getInstance().build("/app/LoginActivity").navigation()
                        //保存当前打开过的记录，下次不打开

                        SPUtils.getInstance().put("isOpen",true)
                    }
                }
            },0,1000)
        }*/

        //广告页一直展示，，如果账户登陆过，直接进入主页面   如果未登陆过，跳转到登录界面
        timer = Timer()
        timer.schedule(timerTask {
            handler.post {
                time--
                binding.djs.setText("倒计时：$time 秒")
                if(time==0){
                    timer.cancel()//取消定时器
                    finish()//结束当前界面，返回不展示这个界面
                   if(SPUtils.getInstance().getString("token").isNotEmpty()){
                       ARouter.getInstance().build("/app/MainActivity").navigation()
                   }else{
                       ARouter.getInstance().build("/app/LoginActivity").navigation()
                   }
                }
            }
        },0,1000)

    }

    override fun initData() {
    }

}